﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using Model.TrainModelHelper;
using System.Configuration;
using Model.SystemManage;
namespace DAL.TrainDALhelp
{
   public  class GradeDAL
    {
        private static string ConStr = ConfigurationManager.ConnectionStrings["ConStr"].ToString();
        private static SqlConnection conn = new SqlConnection(ConStr);
        public List<GradeModel> GradList()
        {
            conn.Open();
            SqlCommand comd = new SqlCommand("", conn);
            SqlDataReader read = comd.ExecuteReader();
            List<GradeModel> lis = new List<GradeModel>();
            while (read.Read())
            {
                GradeModel str = new GradeModel();




                lis.Add(str);


            }
            read.Close();
            conn.Close();
            return lis;

        }
        public List<Dept_Model> DepList()
        {
            conn.Open();
            SqlCommand comd = new SqlCommand("select * from Dept_Tab", conn);
            SqlDataReader read = comd.ExecuteReader();
            List<Dept_Model> lis = new List<Dept_Model>();
            while (read.Read())
            {
                Dept_Model str = new Dept_Model();


                str.DeptID = Convert.ToInt32(read["DeptID"]);

                str.DeptName = read["DeptName"].ToString();

                lis.Add(str);


            }
            read.Close();
            conn.Close();
            return lis;

        }
        public List<EmployeeLoginInfo_Model> EmployeeLoginInfoList()
        {
            conn.Open();
            SqlCommand comd = new SqlCommand("select EmployID,EmployName from dbo.EmployeeLoginInfo_Tab ", conn);
            SqlDataReader read = comd.ExecuteReader();
            List<EmployeeLoginInfo_Model> lis = new List<EmployeeLoginInfo_Model>();
            while (read.Read())
            {
                EmployeeLoginInfo_Model str = new EmployeeLoginInfo_Model();


                str.EmployID = Convert.ToInt32(read["EmployID"]);

                str.EmployName = read["EmployName"].ToString();

                lis.Add(str);


            }
            read.Close();
            conn.Close();
            return lis;

        }
       public  int  GardAdd(GradeModel s1)
        {
            conn.Open();
            SqlCommand comd = new SqlCommand("Insert into GradeTable Values ('" + s1.staff_Id + "','" + s1.Score1 + "','" + s1.GradTime + "',"+s1.Grad_ProId+",0)", conn);

            var i = comd.ExecuteNonQuery();
            conn.Close();
            return i;
        }
       public int GradState( int id )
       {

           SqlCommand comd = new SqlCommand("select count(*) from GradeTable where staff_id =id and Grad=0", conn);

           var i = comd.ExecuteScalar();
           conn.Close();
           if (i != null)
           {
               int a = Convert.ToInt32(i);
               if (a > 0)
               {
                   return 0;
               }
               else
               {
                   return 1;
               }
           }
           else
           {
               return 1;
           }
          
       }

    }
}
